home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <netinet/in.h>
- #include <stdio.h>
-
- extern char *malloc();
-
- /* zoek een host met de gegeven naam in de file /etc/hosts */
- struct hostent *gethostbyname(host_name)
- char *host_name;
- {
- struct hostent *host;
- char **aliases, **addr_list;
-
- char tmp[100]; /* should be long enough */
- int a, b, c, d, count;
- FILE *f;
- char address[20]; /* 16+4 should be long enough */
- f = fopen(":etc/hosts","r");
- if(!f) {
- fprintf(stderr, "Could not open :etc/hosts\n");
- return NULL;
- }
- while((count = fscanf(f, "%d.%d.%d.%d %s", &a, &b, &c, &d, tmp)) == 5)
- if(!strcmp(host_name, tmp))
- break;
- if(count != 5) {
- fclose(f);
- return NULL;
- }
- fclose(f);
- /* ok data was read, now fill the hostent structure with it */
- host = (struct hostent *) malloc(sizeof(struct hostent));
- if(!host)
- return NULL;
- host->h_name = host_name;
- aliases = (char **) malloc(4); /* 1 pointer naar string */
- if(!aliases)
- return NULL;
- aliases[0] = '\0'; /* geen aliases */
- host->h_aliases = aliases;
- addr_list = (char **) malloc(4); /* 1 pointer naar string */
- if(!addr_list)
- return NULL;
- sprintf(address, "%d.%d.%d.%d", a, b, c, d);
- addr_list[0] = malloc(strlen(address)+1);
- strcpy(addr_list[0], address);
- host->h_addr_list = addr_list;
- host->h_addrtype = AF_INET;
- host->h_length = strlen(address); /* lengte van address */
- return host;
- }
-
-
- int gethostname(name, namelen)
- char *name;
- int namelen;
- {
- FILE *f;
- char tmp[100]; /* should be long enough */
- int a,b,c,d;
-
- f = fopen(":etc/hosts","r");
- if(!f) {
- fprintf(stderr, "Could not open :etc/hosts\n");
- return -1;
- }
- if(fscanf(f, "%d.%d.%d.%d %s", &a, &b, &c, &d, tmp) != 5) {
- fprintf(stderr, "illegal line found in :etc/hosts");
- fclose(f);
- return -1;
- }
- if(strlen(tmp) > namelen) {
- fclose(f);
- return -1;
- }
- strcpy(name, tmp);
- fclose(f);
- return 0;
- }
-
- int getpeername(s, name, namelen)
- int s;
- struct sockaddr *name;
- int *namelen;
- { /* put the name of the host to which the socket is connected in name */
- char *this_host = "6.6.6.6";
-
- *namelen = strlen(this_host);
- strcpy(name->sa_data, this_host);
-
- return 0; /* success */
- }
-
- char *inet_ntoa(in)
- struct in_addr in;
- {
- static char *address = "6.66.66.6";
- return address;
- }
-
- /*
- 6 = 0x06
- 66 = 0x42
- */
- unsigned long inet_addr(cp)
- char *cp;
- {
- return 0x06424206;
- }
-